package com.aboo.users.service;

import com.aboo.users.domain.UserPO;
import com.aboo.users.mapper.UserMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    public List<UserPO> getUser(String pageNo, String pageSize) {
        if (StringUtils.isNotBlank(pageSize)) {
            int pageNoI = Integer.parseInt(StringUtils.defaultIfBlank(pageNo, "1"));
            int pageSizeI = Integer.parseInt(pageSize);
            PageHelper.startPage(pageNoI, pageSizeI);
        }
        return userMapper.selectUser();
    }

    public int saveUser(UserPO user) {
        if (user == null) {
            return 0;
        }

        return userMapper.insertUser(user);
    }

    public int modifyUser(UserPO user) {
        return userMapper.updateUser(user);
    }

}
